<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>登录页面</title>
  <script src="../util/axios.min.js"></script>
  <style>
    /* 重置默认的边距和填充 */
    * {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
    }

    body {
      font-family: Arial, sans-serif;
      background: url('../images/vmbg2.png') center/cover no-repeat fixed; /* 使用背景图像 */
      display: flex;
      justify-content: center;
      align-items: center;
      height: 100vh;
      margin: 0;
    }

    .login-container {
      text-align: center;
    }

    .login-card {
      background: rgba(255, 255, 255, 0.8); /* 添加半透明的背景颜色 */
      box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.2);
      border-radius: 8px;
      padding: 20px;
      width: 300px;
      max-width: 100%;
    }

    .login-card h2 {
      color: #333;
    }

    .input-container {
      margin-bottom: 20px;
    }

    label {
      display: block;
      text-align: left;
      color: #555;
      font-weight: bold;
    }

    input[type="text"],
    input[type="password"] {
      width: 100%;
      padding: 10px;
      border: 1px solid #ccc;
      border-radius: 5px;
    }

    .password-toggle {
      position: absolute;
      top: 50%;
      right: 10px;
      transform: translateY(-50%);
      cursor: pointer;
    }

    .button-container {
      display: flex;
      justify-content: space-between;
      align-items: center;
    }

    button{
      background: linear-gradient(to right,  #007bff, #0056b3);
      color: #fff;
      padding: 10px 20px;
      border: none;
      border-radius: 5px;
      cursor: pointer;
      transition: background 0.3s ease;
    }

    button:hover {
      background: linear-gradient(to left,  #007bff, #0056b3);
    }

    p {
      margin-top: 10px;
    }
  </style>
</head>
<body>
<div class="login-container">
  <div class="login-card">
    <form>
      <div class="input-container">
        <label for="username">用户名</label>
        <input type="text" id="username"  placeholder="请输入用户名" required>
      </div>

      <div class="input-container">
        <label for="password">密码</label>
        <input type="password" id="password"  placeholder="请输入密码" required>
        <span class="password-toggle"></span>
      </div>
      <div class="input-container">
        <label for="name">姓名</label>
        <input type="text" id="name"  placeholder="请输入姓名" required>
      </div>
      <div class="input-container">
        <label for="phone">联系方式</label>
        <input type="text" id="phone"  placeholder="请输入联系方式" required>
      </div>

      <div class="button-container">
        <button type="button" onclick="update()">保存</button>
        <button type="reset">重置</button>
      </div>
    </form>
  </div>
</div>
</body>
<script >
  function update() {
    const username=document.getElementById("username").value
    const password=document.getElementById("password").value
    const name=document.getElementById("name").value
    const phone=document.getElementById("phone").value
    // 添加请求拦截器
    axios.interceptors.request.use(function (config) {
      config.headers.token = localStorage.getItem("token")
      // 在发送请求之前做些什么
      return config;
    });
    axios({
      method: 'post',
      url: 'http://localhost:8080/user/updateUser',
      data: {
        username: username,
        password: password,
        name: name,
        phone: phone
      }
    }).then((resp)=>{
      if (resp.data.code===200){
        localStorage.clear()
        alert("修改成功 请重新登录")
        top.location.href="login.html";
      }else if (resp.data.code===209){
        alert(resp.data.message)
      }
    });
  }
</script>
</html>
